package com.itheima.controller;


import com.itheima.pojo.PageResult;
import com.itheima.pojo.Result;
import com.itheima.pojo.Student;
import com.itheima.pojo.StudentQueryParam;
import com.itheima.service.StudentService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RequestMapping("/students")
@RestController
public class StudentController {

    @Autowired
    private StudentService studentService;

    //分页查询
    @GetMapping()
    public Result page(StudentQueryParam studentQueryParam){
        PageResult pageResult = studentService.page(studentQueryParam);
        return Result.success(pageResult);
    }


    //删除系列
    @DeleteMapping ("/{ids}")
    public Result delete(@PathVariable List<Integer> ids){
      studentService.deleteByIds(ids);
        return Result.success();
    }

    @PostMapping
    public Result save(@RequestBody Student student){
        studentService.save(student);
        return Result.success();
    }



    @GetMapping("/{id}")
    public Result getById(@PathVariable Integer id){
        return Result.success(studentService.getById(id));
    }

    @PutMapping
    public Result update(@RequestBody Student student){
        studentService.update(student);
        return Result.success();
    }


    @PutMapping("/violation/{id}/{score}")
    public Result updateViolation(@PathVariable Integer id,@PathVariable Integer score){
        studentService.updateViolation(id,score);
        return Result.success();
    }



}
